Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GDScript: Fix annotation parsing adding new annotation entries #98146

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

HolonProduction
Copy link
Member

Fixes #98145

The code was indexing the annotation map regardless of the previous check which apparently introduces new entries. So the right error was only emitted for the first parsing but for any subsequent parsing the name would be present in the map.

@HolonProduction HolonProduction requested a review from a team as a code owner October 13, 2024 17:13
@HolonProduction HolonProduction force-pushed the this-error-does-not-apply-to-unrecognized-annotations branch from d1a2b6a to cbc62c5 Compare October 13, 2024 17:14
@HolonProduction HolonProduction changed the title GDScript: Fix annotation parsing adding new annotations entires GDScript: Fix annotation parsing adding new annotation entries Oct 13, 2024
@dalexeev dalexeev added this to the 4.4 milestone Oct 13, 2024
Copy link
Member

@dalexeev dalexeev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me. Please add a test.

@HolonProduction HolonProduction force-pushed the this-error-does-not-apply-to-unrecognized-annotations branch from cbc62c5 to a997e69 Compare October 13, 2024 20:17
@HolonProduction HolonProduction requested a review from a team as a code owner October 13, 2024 20:17
@dalexeev
Copy link
Member

which apparently introduces new entries

It's probably because of this:

const TValue &operator[](const TKey &p_key) const {
uint32_t pos = 0;
bool exists = _lookup_pos(p_key, pos);
CRASH_COND(!exists);
return elements[pos]->data.value;
}
TValue &operator[](const TKey &p_key) {
uint32_t pos = 0;
bool exists = _lookup_pos(p_key, pos);
if (!exists) {
return _insert(p_key, TValue())->data.value;
} else {
return elements[pos]->data.value;
}
}

For some reason, the non-const overload is chosen, although we meant reading here, not writing. Also, we recently fixed a similar bug for typed dictionaries (see #96797).

// WARNING: This operator does not validate the value type. For scripting/extensions this is
// done in `variant_setget.cpp`. Consider using `set()` if the data might be invalid.
Variant &Dictionary::operator[](const Variant &p_key) {

It's a shame that C++ has such a limited and confusing behavior. Maybe we should abandon creating new elements using operator[] in favor of the insert() method? Same for writing and set(), but it will probably be inconvenient.

@HolonProduction
Copy link
Member Author

Done! Really should start making a habit out of adding tests 😅

@HolonProduction HolonProduction force-pushed the this-error-does-not-apply-to-unrecognized-annotations branch from a997e69 to 140c6a6 Compare October 13, 2024 20:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

GDScript emits wrong error for unkown annotations
2 participants